package structural_pattern.facade_pattern;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

/**
 * 文件读取类：子系统类
 */
public class FileReader {
    public String read(String fileNameSrc) {
        System.out.println("读取文件，获取明文"+new File(fileNameSrc).exists());
        StringBuffer sb = new StringBuffer(); //线程安全
        try {
            FileInputStream fileInputStream = new FileInputStream(fileNameSrc);
            int data;
            while ((data = fileInputStream.read()) != -1) {
                sb.append((char) data);
            }
            fileInputStream.close();
            System.out.println(sb.toString());
        } catch (FileNotFoundException e) {
            System.out.println("文件不存在!");
        } catch (IOException e) {
            System.out.println("文件操作错误!");
        }
        return sb.toString();
    }
}
